<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="../../common/common.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>云众科技网上预约挂号系统</title>
	</head>
	<body>
		<div class="container">
			<form class="form-horizontal text-center" style="position:relative;"  name="infoForm" action="javascript:doSub()" method="post" >
				<input type="hidden" name="professionalId" value="${prof.professionalId}">
				<div class="container" >
					<div class="form-group" >
						<label class="control-label col-sm-2 col-md-2">职位名称:</label>
						<div class="col-md-4 col-sm-4">
							<input class="form-control" name="professionalName" required value="${prof.professionalName}" placeholder="请输入职位姓名" />
						</div>	
					</div>
					<div class="form-group">
						<label class="control-label col-sm-2 col-md-2">所属科室:</label>
						<div class="col-md-4 col-sm-4">
							<select name="dpId" class="form-control" >
								<option value="">===请选择===</option>
								<c:forEach items="${deptList}" var="dept">
									<option value="${dept.dpId }" ${dept.dpId==prof.dpId?"selected":"" }>${dept.dpName }</option>
								</c:forEach>
							</select>
						</div>
					</div>
					<div class="form-group" >
						<label class="control-label col-sm-2 col-md-2">职位服务费:</label>
						<div class="col-md-4 col-sm-4">
							<input class="form-control" name="professionalFee" required value="${prof.professionalFee}" placeholder="请输入服务费" onkeyup="value=value.replace(/[^\w\/]/ig,'')"/>
						</div>	
					</div>
					<div class="form-group">
						<div class="col-lg-4 col-md-4 col-sm-2 col-xs-2">
							
						</div>
						<div class=" col-lg-4 col-md-4 col-sm-8 col-xs-8" >
							<div class="col-md-6 col-sm-6">
								<button class="form-control btn-primary" type="submit" >提交</button>
							</div>
							<div class="col-md-6 col-sm-6">
								<button class="form-control btn-primary" type="button" onclick="goBack()" >返回</button>
							</div>
						</div>
						<div class="col-lg-4 col-md-4 col-sm-2 col-xs-2">
							
						</div>
					</div>
				</div>
			</form>
			<hr/>
		</div>
		<!-- 模态框 -->
		<div class="modal fade" id="myModal" tabindex="-1" role="dialog" 
		   aria-labelledby="myModalLabel" aria-hidden="true">
		   <div class="modal-dialog modal-lg">
		      <div class="modal-content">
		         <div class="modal-header" style="background-color: rgba(0,0,0,0.1)">
		            <button type="button" class="close" data-dismiss="modal" 
		               aria-hidden="true">×
		            </button>
		            <h4 class="modal-title" id="myModalLabel">
		              	确认提交
		            </h4>
		         </div>
		         <div class="modal-body text-center" id="modalBody">
		           	是否确认提交?
		         </div>
		         <div class="modal-footer" id="modalFooter">
		            <button type='button' class='btn btn-default' data-dismiss='modal'>关闭</button>
		         </div>
		      </div>
		   </div>
		</div>
	</body>
	<script type="text/javascript">
		
		//提交方法
		function doSub(){
			$("input").css("background-color","white");
			//设置开关
			var Switch = false ;
			//判断服务费是否为数字
			var professionalFee = $("input[name='professionalFee']").val();
			var reg = /^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$/;
			if(!reg.test(professionalFee)){
				$("#myModalLabel").html("提交失败");
				$("#modalBody").html("请输入正确的服务费,必须是大于零的数!");
				$("#myModal").modal('show');
				$("input[name='professionalFee']").css("background-color","wheat");
				return;
			}
			//判断是否选择了科室
			if($("select[name='dpId']").val()==""){
				$("#myModalLabel").html("提交失败");
				$("#modalBody").html("科室不能为空!");
				$("#myModal").modal('show');
				$("select[name='dpId']").css("background-color","yellow");
				return;
			}else{
				var professionalName = $("input[name='professionalName']").val();
				var dpId = $("select[name='dpId']").val();
				//判断职称名是否重复
				if(professionalName == "${prof.professionalName}" && dpId == "${prof.dpId}" ){
					Switch = false;
				}else{
					$.ajax({
						url:"<%=request.getContextPath()%>/sys/judgeProfessionalName",
						data:{professionalName:professionalName,dpId:dpId},
						dataType:"json",
						async:false,
						type:"post",
						success:function(r){
							
							if(r.success == "false"){
								$("#myModalLabel").html("提交失败");
								$("#modalBody").html("该职务名称已存在与选择科室中,请重新输入或换科室!");
								$("#myModal").modal('show');
								$("input[name='professionalName']").css("background-color","wheat");
								Switch = true;
							}else if(r.success == "empty"){
								$("#myModalLabel").html("提交失败");
								$("#modalBody").html("该职务名不可用!");
								$("#myModal").modal('show');
								$("input[name='professionalName']").css("background-color","wheat");
								Switch = true;
							}
						}
					})
				}
			}
			//通过判定switch来决定是否结束
			if(Switch){
				return;
			}else{
				bootbox.confirm("确定要提交吗?", function(result) {
					if(result){
						$("form[name='infoForm']").attr("action","<%=request.getContextPath()%>/sys/saveOrUpdateProfessional");
						$("form[name='infoForm']").submit();
					}
				})
			}
		}
	</script>
</html>